/* GUI CONVERTED from ecpsfm03.p (converter v1.75) Mon Nov 20 19:08:29 2000 */
/* ecpsfm03.p - BOM SUMMARY SUB-ROUTINE                                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/*K0M7*/
/*V8:ConvertMode=Report                                                      */
/* REVISION: 7.4      LAST EDIT: 04/23/95       MODIFIED BY: QZL *H0DB*      */
/* REVISION: 8.6      LAST EDIT: 10/08/97       MODIFIED BY: mzv *K0M7*      */
/* REVISION: 8.6      LAST EDIT: 05/29/98       MODIFIED BY: *K1R6* A.Shobha */
/* REVISION: 8.6      LAST MODIFIED: 01/28/99   BY: *K1Z2* Santhosh Nair     */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder     */
/* REVISION: 9.1      LAST MODIFIED: 11/16/00   BY: *M0V3* Mark Christian    */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

     {mfdeclre.i}

/*K1R6 /*K0M7*/ {wbrp02.i}*/

         define input parameter comp like ps_comp.
         define input parameter ecmnbr like ecm_nbr.

/*K1Z2** BEGIN DELETE **
 *       define shared workfile psmstr like ps_mstr.
 *       define shared variable wkfl_no as integer.
 *       define shared variable maxwkfl as integer.
 *K1Z2** END DELETE */

/*K1Z2*/ define shared temp-table psmstr like ps_mstr.
         define variable level as integer initial 1 no-undo.
         define variable record as integer extent 1000 no-undo.
         define variable i as integer no-undo.
         define variable effstart as date no-undo.
         define variable effend as date no-undo.
         define variable eff_start as date extent 1000 no-undo.
         define variable eff_end as date extent 1000 no-undo.

         find first ps_mstr
            use-index ps_parcomp
            where ps_mstr.ps_par = comp
            no-lock no-error.

         repeat:

            if not available ps_mstr then do:

               repeat:

                  level = level - 1.

                  if level < 1 then leave.

                  find ps_mstr where recid(ps_mstr) = record[level]
                  no-lock no-error.

                  comp = ps_mstr.ps_par.

                  if level    = 1 then
                     effstart = ?.
                  else
                     effstart = eff_start[level - 1].

                  if level = 1 then
                     effend   = ?.
                  else
                     effend   = eff_end[level - 1].

                  find next ps_mstr
                     use-index ps_parcomp
                     where ps_mstr.ps_par = comp
                     no-lock no-error.

                  if available ps_mstr then leave.

               end. /* REPEAT */

            end. /* IF NOT AVAILABLE ps_mstr */

            if level < 1 then leave.

            if today >= max(if effstart = ? then low_date else effstart,
            if ps_start <> ? then ps_start else low_date) and
            today <= min(if effend = ? then hi_date else effend,
            if ps_end <> ? then ps_end else hi_date)
            then do:

               find first psmstr
                  where psmstr.ps_par       = ps_mstr.ps_par
                  and   psmstr.ps_comp      = ps_mstr.ps_comp
                  and   psmstr.ps_ref       = ps_mstr.ps_ref
                  and   psmstr.ps_start     = today
                  no-error.

               if not available psmstr
               then do:

                  create psmstr.

                  assign
                     psmstr.ps_par       = ps_mstr.ps_par
                     psmstr.ps_comp      = ps_mstr.ps_comp
                     psmstr.ps_ref       = ps_mstr.ps_ref
                     psmstr.ps_start     = today
                     psmstr.ps_end       = today + 1501
                     psmstr.ps_qty_per_b = ps_mstr.ps_qty_per_b
                     psmstr.ps_qty_per   = ps_mstr.ps_qty_per
                     psmstr.ps_ps_code   = ps_mstr.ps_ps_code
                     psmstr.ps_scrp_pct  = ps_mstr.ps_scrp_pct.

                  if recid(psmstr) <> -1 then.

/*K1Z2** BEGIN DELETE  **
 *                wkfl_no = wkfl_no + 1.
 *                if wkfl_no > maxwkfl then do:
 *                   {mfmsg.i 5671 2}
 *                   return.
 *                end.
 *K1Z2** END DELETE  */

/*M0V3** BEGIN DELETE
 *
 *                 for each ecd1_det
 *                    no-lock
 *                    where ecd1_nbr = ecmnbr
 *                    and   ecd1_par = psmstr.ps_par
 *                    and ecd1_comp = psmstr.ps_comp:
 *
 *                    {gprun.i ""ecpsfm04.p""
 *                       "(input recid(ecd1_det),
 *                         input ecmnbr)"}
 *
 *                   end. /* FOR EACH ecd1_det */
 *
 *M0V3** END DELETE */

               end. /* IF NOT AVAILABLE psmstr */

            end. /* IF today > max(... */

/*M0V3*/    for each ecd1_det
/*M0V3*/       fields (ecd1_comp ecd1_nbr ecd1_par)
/*M0V3*/       where ecd1_nbr  = ecmnbr
/*M0V3*/       and   ecd1_comp = ps_mstr.ps_comp
/*M0V3*/       and   ecd1_par  = ps_mstr.ps_par
/*M0V3*/       no-lock :

/*M0V3*/          {gprun.i ""ecpsfm04.p""
/*M0V3*/             "(input recid(ecd1_det),
/*M0V3*/               input ecmnbr)"}

/*M0V3*/    end. /* FOR EACH ecd1_det */

            if (ps_mstr.ps_ps_code = ""   or
                ps_mstr.ps_ps_code = "X") and
                ps_mstr.ps_qty_per_b <> 0 and
                level < 1000
            then do:

               record[level] = recid(ps_mstr).

               eff_start[level] = max(effstart,ps_mstr.ps_start).

               if effstart = ? then
                  eff_start[level] = ps_mstr.ps_start.

               if ps_mstr.ps_start = ? then
                  eff_start[level] = effstart.

               eff_end[level] = min(effend,ps_mstr.ps_end).

               if effend   = ? then
                  eff_end[level] = ps_mstr.ps_end.

               if ps_mstr.ps_end   = ? then
                  eff_end[level] = effend.

               comp = ps_mstr.ps_comp.

               find pt_mstr no-lock
                  where pt_part = ps_mstr.ps_comp
                  no-error.

               if available pt_mstr and
                  pt_bom_code <> ""
               then
                  comp = pt_bom_code.

               level = level + 1.

               find first ps_mstr
                  use-index ps_parcomp
                  where ps_mstr.ps_par = comp
                  no-lock no-error.

            end. /* IF ps_mstr.ps_ps_code = "" */

            else

               find next ps_mstr
                              use-index ps_parcomp
                  where ps_mstr.ps_par = comp
                  no-lock no-error.

        end. /* REPEAT */

/*K1R6 /*K0M7*/ {wbrp04.i} */
